package com.xk.app_home.activity

import android.graphics.Color
import android.os.Bundle
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils

import com.xk.app_home.fragment.HomeFragment

import com.google.android.material.navigation.NavigationView
import com.xk.app_home.R
import com.xk.app_home.databinding.ActivityHomeBinding
import com.example.activity.BaseActivity
import com.example.utils.CommonUtils
import com.example.utils.StatusBarUtil
import com.xk.app_mine.view.fragment.Mine2Fragment



@Route(path = "/app/home")
class MainActivity : BaseActivity() {

    private lateinit var binding: ActivityHomeBinding
    fun setToolbar(){
        setNoTitle()
        setSupportActionBar(binding.drawEnd.toolbar)
        val actionBar = supportActionBar
        actionBar?.setDisplayShowTitleEnabled(false)
    }
    var set =1;
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityHomeBinding.inflate(layoutInflater)
        setBind(binding);
        setToolbar()
        val uriStr = intent.getStringExtra(ARouter.RAW_URI)
        LogUtils.d(uriStr)
        binding.drawEnd.llTitleMenu.setOnClickListener {
            binding.drawerLayout.openDrawer(binding.drawView)
        }
        binding.drawEnd.llHome.setOnClickListener {
            binding.drawEnd.tvHome.setTextColor(Color.BLUE)
            binding.drawEnd.tvProject.setTextColor(Color.WHITE)
            binding.drawEnd.tvTree.setTextColor(Color.WHITE)
            binding.drawEnd.tvMide.setTextColor(Color.WHITE)
            var fragmentManager:FragmentManager = supportFragmentManager
            val fragmentTra2:FragmentTransaction  = fragmentManager.beginTransaction()
            fragmentTra2.replace(R.id.nav_host_fragment_activity_main, HomeFragment(),"one")
            fragmentTra2.commit()
        }
        binding.drawEnd.llTree.setOnClickListener {
            binding.drawEnd.tvTree.setTextColor(Color.BLUE)
            binding.drawEnd.tvProject.setTextColor(Color.WHITE)
            binding.drawEnd.tvHome.setTextColor(Color.WHITE)
            binding.drawEnd.tvMide.setTextColor(Color.WHITE)
            var fragmentManager:FragmentManager = supportFragmentManager
            val fragmentTra3:FragmentTransaction  = fragmentManager.beginTransaction()
        //    fragmentTra3.replace(R.id.nav_host_fragment_activity_main,TreeFragment(),"two")
            fragmentTra3.commit()
        }
        binding.drawEnd.llMide.setOnClickListener {
            binding.drawEnd.tvMide.setTextColor(Color.BLUE)
            binding.drawEnd.tvProject.setTextColor(Color.WHITE)
            binding.drawEnd.tvTree.setTextColor(Color.WHITE)
            binding.drawEnd.tvHome.setTextColor(Color.WHITE)
            var fragmentManager:FragmentManager = supportFragmentManager
            val fragmentTra4:FragmentTransaction  = fragmentManager.beginTransaction()
            fragmentTra4.replace(R.id.nav_host_fragment_activity_main, Mine2Fragment(),"four")
            fragmentTra4.commit()
        }
        binding.drawView.setNavigationItemSelectedListener(OnNavigationItemSelectedListener)
    }
    override fun initStatusBar() {
        StatusBarUtil.setColorNoTranslucentForDrawerLayout(
            this@MainActivity,
            binding.drawerLayout,
            CommonUtils.getColor(this, com.xk.app_home.R.color.green)
        )
        val layoutParams: ViewGroup.LayoutParams = binding.drawEnd.viewStatus.layoutParams
        layoutParams.height = StatusBarUtil.getStatusBarHeight(this)
        binding.drawEnd.viewStatus.layoutParams = layoutParams
    }

    var OnNavigationItemSelectedListener = NavigationView.OnNavigationItemSelectedListener{
        if(it.itemId== R.id.nav_camera){
            ARouter.getInstance().build("/app/CameraActivity").navigation()
        }else if(it.itemId==R.id.nav_video){
            ARouter.getInstance().build("/app/VideoActivity").navigation()
        }else if(it.itemId== R.id.nav_slideshow){
            ARouter.getInstance().build("/cameraface/FaceActivity").navigation()
        }
        return@OnNavigationItemSelectedListener true
    }

    override fun onResume() {
        super.onResume()
        LogUtils.d("onResume")
    }

}